home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d18 / tp_asm22.arc / HEXBYTE.PAS < prev    next >
Pascal/Delphi Source File  |  1991-04-28  |  2KB  |  69 lines

  1. {═══════════════════════════ HEXBYTE.PAS ════════════════════════════}
  2. { This demonstration illustrates the use of TP&Asm and Turbo Pascal  }
  3. { to develop and verify an assembly language procedure intended for  }
  4. { stand-alone assembly.  The assembly code at 'Hexbyte:' returns     }
  5. { (in AX) a Word containing the 2-byte Ascii representation of the   }
  6. { byte value passed to it in Al.  Use Pascal to Call Hexbyte (via    }
  7. { the Pascal function TestHexByte) and print the result for every    }
  8. { possible input value.                                              }
  9. {═══════════════════════════ HEXBYTE.PAS ════════════════════════════}
  10.  
  11.  
  12. {════════════════════════════ TestHexByte ═══════════════════════════}
  13. {  Pascal Function containing the code to be tested.                 }
  14. {════════════════════════════ TestHexByte ═══════════════════════════}
  15. FUNCTION TestHexByte(SourceByte: BYTE): INTEGER;
  16. {- In the assembly routine it will be convenient to get the -}
  17. {- parameter from Al and to leave the Result in Ax.         -}
  18. CONST
  19.   HexDigits: ARRAY[0..15] OF CHAR = '0123456789ABCDEF';
  20.  
  21. BEGIN
  22.  
  23. Assemble
  24.  
  25.   Mov Al,SourceByte  ; Get parameter
  26.   Call HexByte       ; Call ASSEMBLY procedure
  27.   Mov TestHexByte,Ax ; Put in TestHexByte Function Result
  28.   Pas Exit;          { and Exit }
  29.  
  30.  ;- Here is the precise code we will use in the assembly program -
  31.  ;- Assumes Al = SourceByte on entry, Returns result in Ax
  32.  ;- All other registers are preserved
  33. HexByte:
  34.   Push Bx
  35.   Xor Ah,Ah  ; set Ah = 0 to prevent Divide Overflow
  36.   Mov Bl,010
  37.   Div Bl     ; Al = Quo, Ah = Rem
  38.   Mov Bx,Offset HexDigits
  39.   Xchg Al,Ah
  40.   XlatB
  41.   Xchg Al,Ah
  42.   XlatB
  43.   Pop Bx
  44.   Ret
  45.  ;- End of HexByte code
  46.  
  47.  
  48. Finish:
  49. END; {Assemble}
  50.  
  51. END; {FUNCTION TestHexByte}
  52.  
  53. CONST Result: RECORD
  54.         Len: BYTE;
  55.         Wrd: INTEGER;
  56.       END = (Len:2;Wrd:0);
  57. VAR
  58.   n: BYTE;
  59.   ResultString: STRING[2] Absolute Result;
  60.  
  61. BEGIN {Main Program}
  62.   FOR n := 0 TO 255 DO BEGIN
  63.     WRITE(n:3,' ');
  64.     Result.Wrd := TestHexByte(n);
  65.     WRITE(ResultString,'  ');
  66.   END; {FOR n := 0 TO 255 DO }
  67.   WRITELN;
  68. END. {Main}
  69.